Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ember.A should not modify underlying array #20245

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

wagenet
Copy link
Member

@wagenet wagenet commented Oct 31, 2022

Resolves #20219

@wagenet wagenet marked this pull request as ready for review October 31, 2022 22:38

const emberArrayLastObject = nonEnumerableComputed(function () {
return objectAt(this, this.length - 1);
}).readOnly();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love how we're assigning them to variables here, but I can't find any other good way to get a reference to their CPs.

let proxy = new Proxy(arr, {
get(target, prop /*, _receiver */) {
// These nonEnumerableComputed properties need special handling
if (prop === '[]') {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd have something more generic, but we aren't going to be adding stuff to EmberArray going forwards so this should be fine.

@chriskrycho
Copy link
Contributor

chriskrycho commented Nov 1, 2022

@wagenet note that "Extend Prototypes" is failing on CI.

@wagenet wagenet force-pushed the ember-a-improvements branch from 7dd16a6 to 7aa79fa Compare November 1, 2022 15:11
Copy link
Contributor

@chriskrycho chriskrycho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me, but I'd still really like it if someone who's more familiar with this could give it some 👀 as well. @rwjblue do you have 10 minutes (tops) to look at it?

@wagenet
Copy link
Member Author

wagenet commented Nov 22, 2022

I think I'd like to put this behind a flag. I think (hope) it won't cause issues for people, but who knows what people are actually doing and whether they're relying on the mutating behavior.

@wagenet wagenet force-pushed the ember-a-improvements branch from 7aa79fa to 0b2ab6f Compare November 23, 2022 15:55
@wagenet wagenet force-pushed the ember-a-improvements branch 2 times, most recently from 00ccece to 582831f Compare January 3, 2023 23:16
@jrjohnson
Copy link

I agree that it should go behind a flag. Because many addons call A() on basically everything there are probably lots of components in production today that pass something through an addon helper such as {{map-by "id" this.posts}} and then rely on some prototype pollution elsewhere in a getter or action without realizing that the template code had modified the original this.posts. Being able to opt into this change seems like a good way to find out where the breaks are outside of the full deprecation in emberjs/rfcs#864

@wagenet wagenet force-pushed the ember-a-improvements branch from 582831f to 331a4a6 Compare March 7, 2023 17:12
@MelSumner MelSumner requested review from chriskrycho and a team March 24, 2023 21:27
@locks
Copy link
Contributor

locks commented Aug 4, 2023

@wagenet I'm working on pushing tracked-built-ins to recommended and saw this PR. Is this something we still want to push forward?

@wagenet
Copy link
Member Author

wagenet commented Aug 18, 2023

@locks This was partially motivated by issues Ember Data was having. @runspired what's the status of that stuff?

@runspired
Copy link
Contributor

runspired commented Aug 21, 2023

still needed. iirc the solution for most has been to turn prototype extensions back on

@kategengler
Copy link
Member

Is this still relevant?

@runspired
Copy link
Contributor

@kategengler I believe so

@kategengler
Copy link
Member

@wagenet should we merge then?

@wagenet
Copy link
Member Author

wagenet commented Jan 10, 2024

@kategengler I would like to and it is flagged so it should be safe. That said, I haven't really gotten a proper review from anyone still.

@kategengler
Copy link
Member

@kategengler I would like to and it is flagged so it should be safe. That said, I haven't really gotten a proper review from anyone still.

I don't have a clue here or I would offer you one :) I'm just triaging PRs.

@NullVoxPopuli
Copy link
Contributor

can this be rebasod?

@wagenet wagenet force-pushed the ember-a-improvements branch from 331a4a6 to dd75266 Compare January 11, 2024 16:25
// SAFETY: This will return an NativeArray but TS can't infer that.
return NativeArray.apply(arr ?? []) as NativeArray<T>;
if (EMBER_A_NON_MODIFYING) {
// Remove this in Ember 5.0.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.0? 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh... should be 6.0 now, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants